package com.atguigu.gulimallcart.vo;

import java.math.BigDecimal;
import java.util.List;

public class Cart {
    private List<CartItem> items;
    private Integer countNum;//商品数据
    private Integer countType;//商品类型数量
    private BigDecimal totalAmount;//商品总价
    private BigDecimal reduce = new BigDecimal(0);//减免价格
    boolean allCheck = true; //全选

    //有一个购物项未选，全选就为false,提供给前端cartList.html页面使用。
    public boolean isAllCheck() {
        boolean flag = true;
        if (items != null && !items.isEmpty()) {
            for (CartItem item : items) {
                if (!item.getCheck()) {
                    flag=false;
                    break;
                }
            }
        }
        return flag;
    }

    public void setAllCheck(boolean allCheck) {
        this.allCheck = allCheck;
    }

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        if (items != null && !items.isEmpty()) {
            for (CartItem item : items) {
                count += item.getCount();

            }
        }
        return count;
    }


    public Integer getCountType() {
        int count = 0;
        if (items != null && !items.isEmpty()) {
            for (CartItem item : items) {
                count += 1;

            }
        }
        return count;

    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal(0);
        if (items != null && !items.isEmpty()) {
            for (CartItem item : items) {
                if (item.getCheck()) {
                    amount = amount.add(item.getTotalPrice());
                }
            }
        }
        return amount.subtract(reduce);
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
